<template>
    <div id="main" ref="main" style="width: 100%;height: 100%;"></div>
</template>
<sty>


</sty>
<script>

import axios from 'axios';
import * as echarts from 'echarts'

export default {
    mounted() {
        this.initData();
    },
    methods: {

        initData() {
            // 基于准备好的dom，初始化echarts实例
            // var myChart = echarts.init(document.getElementById('main'));//如果节点使用id定义
            var myChart = echarts.init(this.$refs.main);//如果节点使用ref定义
            axios.get("http://192.168.124.96:9090/getBarData").then(res => {
                if (res.data.code != 0) {
                    this.$message({
                        type: "error",
                        message: res.data.msg
                    })
                    this.$router.replace("/")
                    return;
                }
                // 绘制图表
                myChart.setOption({
                    title: {
                        text: '各月份收入统计',
                        subtext: 'Fake Data',
                        left: 'center'
                    },
                    tooltip: {},
                    xAxis: {
                        data: res.data.obj.x
                    },
                    yAxis: {  },
                    series: [
                        {
                            name: '销量',
                            type: 'bar',
                            data: res.data.obj.y
                        }
                    ]
                });
            })


        }
    }
}
</script>